package com.cm.behavior.strategy.example2;

import java.util.HashMap;
import java.util.Map;

/**
 * @author gcm
 * @date 2024/5/13 16:35
 */
public class StrategyContext {
    private static final Map<String, Strategy> REGISTER_MAP = new HashMap<>();
    static {
        Hotel.getInstance();
        Waimai.getInstance();
    }
    /**
     * 注册策略
     *
     * @param rewardType 模式类型
     * @param strategy   策略
     */
    public static void registerStrategy(String rewardType, Strategy strategy) {
        REGISTER_MAP.putIfAbsent(rewardType, strategy);
    }

    /**
     * 获取策略
     *
     * @param rewardType 模式类型
     * @return 结果
     */
    public static Strategy getStrategy(String rewardType) {
        return REGISTER_MAP.get(rewardType);
    }

    public static void main(String[] args) {
        Strategy strategy = StrategyContext.getStrategy("waimai");
        strategy.issue("奖励");
    }
}
